//
//  UCSwitchSetting.swift
//  UICreate
//
//  Created by 范晓鑫 on 2021/10/27.
//

import UIKit

extension UCSetting where TargetType: UISwitch {
    ///选中颜色
    public static func tint(on color: UIColor?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.onTintColor = color
        })
    }
    ///开关的颜色
    public static func tint(thumb color: UIColor?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.thumbTintColor = color
        })
    }
    ///选中图片
    public static func image(on image: UIImage?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.onImage = image
        })
    }
    ///不选中图片
    public static func image(off image: UIImage?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.offImage = image
        })
    }
    ///title
    @available(iOS 14.0, *)
    public static func text(_ text: String?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.title = text
        })
    }
    ///preferredStyle
    @available(iOS 14.0, *)
    public static func style(_ style: UISwitch.Style) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.preferredStyle = style
        })
    }
    ///开关
    public static func on(_ isOn: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.isOn = isOn
        })
    }
}
